﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

namespace Safover.LidarCollector.Core
{
    internal class RotaryTableOpenedStateController : BaseRotaryTableController
    {
        public override RotaryTableStatus RotaryTableStatus => RotaryTableStatus.Opened;

        public override bool CanClose => true;

        public override bool CanOperate => true;

        public RotaryTableOpenedStateController(RotaryTableDevice rotaryTable) : base(rotaryTable)
        { }

        public override bool TryClose()
        {
            try
            {
                Device.CloseSerialPort();
                return true;
            }
            finally
            {
                SetStatus(RotaryTableStatus.Closed);
            }
        }

        public override bool TryMoveHorizontally(float angle)
        {
            SetStatus(RotaryTableStatus.Working);

            try
            {
                return Device.MoveHorizontallyTo(angle);
            }
            finally
            {
                SetStatus(RotaryTableStatus.Opened);
            }
        }

        public override bool TryMoveVertically(float angle)
        {
            SetStatus(RotaryTableStatus.Working);

            try
            {
                return Device.MoveVerticallyTo(angle);
            }
            finally
            {
                SetStatus(RotaryTableStatus.Opened);
            }
        }

        public override bool TryRestoreZero()
        {
            SetStatus(RotaryTableStatus.Working);

            try
            {
                return Device.RestoreZero();
            }
            finally
            {
                SetStatus(RotaryTableStatus.Opened);
            }
        }
    }

}
